﻿using System;
using MyHealthByDesign.Domain;

namespace MyHealthByDesign
{
    /// <summary>
    /// Description:
    /// Master page for website page
    /// 
    /// Author: Sanjeev Shrestha
    /// Date Created: 10/17/2011
    /// 
    /// Other code files referenced:
    /// None.
    /// 
    /// Regression Test Information:
    /// None.
    /// 
    /// Revision History:
    /// 10/20/2011 Sanjeev Shrestha - change logic for user id.
    /// 10/31/2001 Sanjeev Shrestha - add logic to logout
    /// 
    /// 
    /// Known Faults:
    /// None.
    /// </summary>
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        /// <summary>
        /// Page Load event handler - retrieve user from session
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Page displayed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if(Session["User"]!= null)
            {
                User user = (User) Session["User"];
                lblUser.Text = user.Firstname;
                lnkLogout.Text = "[LogOut]";
            }
            else
            {
                lblUser.Text = string.Empty;
            }
            
        }

        /// <summary>
        /// logout button event handler - set user session to null and redirect to default page
        /// 
        /// PreConditions:
        /// None
        /// 
        /// PostConditions:
        /// Page redirected
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lnkLogout_Click(object sender, EventArgs e)
        {
            Session["User"] = null;
            Response.Redirect("../Default.aspx");
        }
    }
}
